/*
    This file is part of Slydini.

    Slydini is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Slydini is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Slydini.  If not, see <http://www.gnu.org/licenses/>.
*/
/* 
 * File:   frameevaluation.h
 * Author: kajetan
 *
 * Created on 28 marzec 2009, 13:55
 */

#ifndef _FRAMEEVALUATION_H
#define	_FRAMEEVALUATION_H

#include "libs.h"
#include "image_structs.h"
#include "myellipse.h"
#include "hand.h"
#include "../configuration/configuration.h"

int inline abs(int k) {
	return (k>=0 ? k : (-k));
}

class FrameEvaluation {
	public:
		static FrameEvaluation *getInstance();

		void update(IplImage *frame);
		//static void trackFingers(IplImage* frame, IplImage* prev_frame, Fingers* fingers, Fingers* prev_fingers, int);
        void updateConfiguration();
		Hand getHand();
	private:
		FrameEvaluation();
		static FrameEvaluation *instance;
		int varColor;
		CvScalar fingerColor;

//		vector<MyEllipse> fingers, prev_fingers;

		Hand hand, hand_prev;
		IplImage *prev_frame;
		int mode;
		int unrecognizedFrames;
		
		//  finds MyEllipses on gray image
		void findMyEllipses(IplImage*, vector<MyEllipse>&);
		//  selects areas in first image of given color and saves a gray image as second image
		void selectPointersArea(IplImage*, IplImage*, CvScalar, bool);
		//  calls selectPointersArea and findMyEllipses
		void chooseEllipsesForFingers(vector<MyEllipse>& ellipses);

		void callLucasKanadeOnFingers(IplImage* frame);

//		void verifyFingers(IplImage* frame, vector<bool>& ver);
		void verifyFingers(IplImage* frame);

		
};

#endif	/* _FRAMEEVALUATION_H */

